package com.resolution.dietaryassessment.view.mydietary.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.resolution.dietaryassessment.databeans.CommonConfig;
import com.resolution.dietaryassessment.R;
import com.resolution.dietaryassessment.databeans.Statistical;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @author By Resolusion
 * @Title: 每日营养所需
 * @Date: 2020/4/8
 * @Time: 15:15
 * @email Res01ution@foxmail.com
 */
public class DailyNutritionFrag extends Fragment {
    @BindView(R.id.re_tx)
    TextView reTx;
    @BindView(R.id.re_tx_kj)
    TextView reTxKj;
    @BindView(R.id.protein_tx)
    TextView proteinTx;
    @BindView(R.id.fat_tx)
    TextView fatTx;
    @BindView(R.id.carbon_tx)
    TextView carbonTx;

    private Unbinder unbinder;
    private int mQuantity,protein,fat,carbon,mQuantity2;

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_daily_nutrition, container, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }

    private void initView() {
        Bundle bundle = getArguments();
        mQuantity = bundle.getInt("热量", 0);
        protein = bundle.getInt("蛋白质", 0);
        fat = bundle.getInt("脂肪", 0);
        carbon = bundle.getInt("碳水", 0);
        mQuantity2 = bundle.getInt("热量2", 0);

        reTx.setText(String.valueOf(mQuantity));
        proteinTx.setText(String.valueOf(protein));
        fatTx.setText(String.valueOf(fat));
        carbonTx.setText(String.valueOf(carbon));
        reTxKj.setText(String.valueOf(mQuantity2));
        sendData();
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    private void sendData(){
        CommonConfig.getInstance().setStatistical(new Statistical(mQuantity,protein,carbon,fat));
    }
}
